﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;
public partial class page_NewsIssueIframe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
  //    在此判断权限

        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Message.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 18)
                    {
                        userFlag = true;
                        break;
                    }
                }

            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
            else
            {
                User user = new User();
                Section section = new Section();
                section.SectionId = 1;
                user.UserId = sucessUser.UserId;
                user.UserName = sucessUser.UserName;
                user.Section = sucessUser.Section;
                TarreOA.TarreOABLL.News news = new TarreOA.TarreOABLL.News();

            }
        }

    }

    protected void BtnSubmit_Click1(object sender, EventArgs e)
    {
        //   取得session 中的 user
        TarreOA.TarreOAModels.User user = (User)Session["user"];

        if (TextNewsTitle.Text.Trim().Equals(""))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('文章标题不能为空')</script>");
            return;
        }
        string Title = TextNewsTitle.Text;

        if (FreeTextBox1.value.Trim().Equals(""))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('文章内容不能为空')</script>");
            return;
        }
        string Detail = FreeTextBox1.value;


        if (!TextNewsTitle.Equals(""))
        {
            if (!Detail.Equals(""))
            {
                int outLineState = 1;

                if (CBoxOutLine.Checked)
                {
                    outLineState = 0;
                }
                TarreOA.TarreOABLL.News news = new TarreOA.TarreOABLL.News();
                if (news.insertNews(Title, Detail, user.UserId, user.Section.SectionId, outLineState))
                {
                    ClientScript.RegisterStartupScript(this.GetType(),"", "<script>alert('插入成功')</script>");
                    Response.Redirect("NewsManagementIframe.aspx");
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('插入失败')</script>");
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('新闻内容不能为空')</script>"); 
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('新闻标题不能为空')</script>");
        }
    }
    protected void BtnCancle_Click(object sender, EventArgs e)
    {
        TextNewsTitle.Text = String.Empty;
        FreeTextBox1.value = String.Empty;
        CBoxOutLine.Checked = false;
    }
}
